package cn.zz.veggie.model.query;

import java.util.Collection;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.zz.comm.core.types.query.CommQuery;
import cn.zz.comm.mybaits.types.BaseQuery;
import cn.zz.veggie.model.domain.Product;
import lombok.Getter;
import lombok.Setter;

/**
 * @author zhongq
 * @since 2024/4/4
 */
@Getter
@Setter
public class ProductQuery extends CommQuery<Integer> implements BaseQuery<Product> {
	public static final int columnIdName = 1;

	public Integer id;
	public Collection<Integer> ids;
	public String name;
	public Collection<String> names;
	public String likeName;
	public Integer status;

	@Override
	public void injectColumn(LambdaQueryWrapper<Product> queryWrapper) {
		switch (column) {
		case columnId -> queryWrapper.select(Product::getId);
		case columnIdName -> queryWrapper.select(Product::getId, Product::getName);
		}
	}

	@Override
	public void injectCondition(LambdaQueryWrapper<Product> queryWrapper) {
		queryWrapper.eq(Objects.nonNull(id), Product::getId, id);
		queryWrapper.in(Objects.nonNull(ids), Product::getId, ids);
		queryWrapper.eq(Objects.nonNull(name), Product::getName, name);
		queryWrapper.eq(Objects.nonNull(status), Product::getStatus, status);
		queryWrapper.in(Objects.nonNull(names), Product::getName, names);
		queryWrapper.like(Objects.nonNull(likeName), Product::getName, likeName);
	}

	@Override
	public void injectOrderBy(Page<Product> page) {
		// order by
		page.addOrder(OrderItem.desc("id"));
	}
}